<template>
  <div class="main-container container-fluid container-limited page-holder">
    <div class="page-title-holder">
      <h2 class="page-title">社区邀请</h2>
    </div>
    <div class="m-t-24">
      您的空间
      <router-link
        class="title link"
        :to="`/${$rp.SPACES}/${invite.product_id}`"
      >
        {{ invite.product_title }}
      </router-link>
      受邀加入社区
      <router-link
        class="title link"
        :to="`/${$rp.COMMUNITIES}/${invite.community_id}`"
      >
        {{ invite.community_title }}
      </router-link>
    </div>
    <div class="cell flex m-t-16">
      <el-button size="small" type="primary" @click="handleInvite(true)">接受</el-button>
      <el-button size="small" @click="handleInvite(false)">拒绝</el-button>
    </div>
  </div>
</template>

<script>
export default {
  name: 'CommunityInvite', // 社区邀请的查看界面
  data() {
    return {
      invite: {},
    };
  },
  created() {
    this.loadInvite();
  },
  methods: {
    // 加载邀请信息
    loadInvite() {
      this.$api.communities.inviteShow({
        communityId: this.$route.query.community_id,
        inviteId: this.$route.query.invite_id,
      }).then(res => this.$set(this, 'invite', res.data))
        .catch(() => {});
    },
    // 处理申请
    handleInvite(state) {
      this.loading = true;
      this.$api.spaces.handleInvite({
        communityId: this.invite.community_id,
        inviteId: this.invite.id,
        spaceId: this.invite.product_id,
        state,
      }).then((res) => { console.log(res); })
        .catch(() => {})
        .then(() => { this.loading = false; });
    },
  },
};
</script>

<style></style>
